package com.trace.communication;

/**
 * Created by denglw on 2020/1/6.<br/>
 * Desc: join机制: 具有使线程排队的效果，在内容使用了wait方法进行控制，而synchronized关键字是采用的对象监视器实现同步
 */
public class Join {

    public static void main(String[] args) {
        String name = Thread.currentThread().getName();
        System.out.println(name + "线程开始运行");
        Thread thread = new Thread(new JoinRunnable());
        thread.start();
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(name + "线程运行结束");
    }

    static class JoinRunnable implements Runnable {
        @Override
        public void run() {
            String name = Thread.currentThread().getName();
            System.out.println(name + "线程正在运行");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(name + "线程运行结束");
        }
    }

}
